const Home = () => import("@/pages/Home");
const Login = () => import("@/pages/Login");
const Register = () => import("@/pages/Register");
const Search = () => import("@/pages/Search");
const NotFound = () => import("@/pages/404");
const Detail = () => import("@/pages/Detail");
const AddCartSuccess = () => import("@/pages/AddCartSuccess");
const ShopCart = () => import("@/pages/ShopCart");
const Trade = () => import("@/pages/Trade");
const Pay = () => import("@/pages/Pay");
const PaySuccess = () => import("@/pages/PaySuccess");
const Center = () => import("@/pages/Center");
const MyOrder = () => import("@/pages/Center/components/MyOrder");
const TeamOrder = () => import("@/pages/Center/components/TeamOrder");
/* 
  在路由表的meta中配置一个属性，代表当前路由下是否展示Footer组件
    可以配置isHidden:true,没有配置的默认isHidden就是false,[使用场景:隐藏的少,展示的多]
    或者配置isShow:true,没有配置的默认isShow就是false[使用场景:展示的少,隐藏的多]
*/
export default [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "/login",
    component: Login,
    name: "Login",
    meta: {
      //   isShow: false,
      isHidden: true,
    },
  },
  {
    path: "/home",
    component: Home,
    name: "Home",
    meta: {
      // isShow: true,
    },
  },
  {
    path: "/search/:keyword?",
    component: Search,
    name: "Search",
    meta: {
      // isShow: true,
    },
  },
  {
    path: "/register",
    component: Register,
    name: "Register",
    // isShow: false,
    meta: {
      isHidden: true,
    },
  },
  {
    path: "/detail/:skuId",
    component: Detail,
    name: "Detail",
  },
  {
    path: "/addCartSuccess",
    component: AddCartSuccess,
    name: "AddCartSuccess",
    beforeEnter: (to, from, next) => {
      if (from.name === "Detail") {
        next();
      } else {
        next("/Search");
      }
    },
  },
  {
    path: "/shopCart",
    component: ShopCart,
    name: "ShopCart",
    meta: {
      isAuth: true,
    },
  },
  {
    path: "/trade",
    component: Trade,
    name: "Trade",
    meta: {
      isAuth: true,
    },
    beforeEnter: (to, from, next) => {
      if (from.name === "ShopCart") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/pay/:orderId",
    component: Pay,
    name: "Pay",
    meta: {
      isAuth: true,
    },
    beforeEnter: (to, from, next) => {
      if (from.name === "Trade") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/paySuccess",
    component: PaySuccess,
    name: "PaySuccess",
    meta: {
      isAuth: true,
    },
    beforeEnter: (to, from, next) => {
      if (from.name === "Pay") {
        next();
      } else {
        next("/shopCart");
      }
    },
  },
  {
    path: "/center",
    component: Center,
    name: "Center",
    meta: {
      isAuth: true,
    },
    redirect: "/center/myOrder",
    children: [
      {
        path: "/center/myOrder",
        name: "MyOrder",
        component: MyOrder,
      },
      {
        path: "/center/teamOrder",
        name: "TeamOrder",
        component: TeamOrder,
      },
    ],
  },
  //任意路由一定是放在最后边的
  {
    path: "/*",
    component: NotFound,
  },
];
